

<div style="position: absolute;top: 120px; left: 450px">
    <font style="font-size: 25px ;color: #e8198b">客户查询：</font>&nbsp;&nbsp;
    客户编号：<input type="text" class="su" id="customerCode" >&nbsp;
    客户名称:<input type="text" class="su" id="name" >&nbsp;
    联系人：<input type="text" class="su" id="contactor">
    <input type="button" value="查询" onclick="selectCustomer()" style="background-color: #1E9FFF">

</div>


<table class="altrowstable" id="userListDiv">
    <thead>
    <tr>
        <th>序号</th>
        <th>客户编号</th>
        <th>客户名称</th>
        <th>联系人</th>
        <th>地址</th>
        <th>邮政编码</th>
        <th>注册日期</th>
        <th>电话</th>
        <th>传真</th>
        <th>操作</th>

    </tr>
    </thead>
    <tbody id="tableBody"></tbody>
</table>

<div  style="position: absolute; margin-top: 0px;padding-left: 700px">
    <ul id="page">分页</ul>
</div>
<input type="button" value="添加" onclick="addCustomer('addUpCustomer.html')" style="margin-left: 600px ; position: absolute; margin-top: 30px; font-size: 18px ; border: #84fab0; background-color: #84fab0">

<script id="customerTemplate" type="text/html">{{each data}}
<tr>
    <td >{{$index+1}}</td>
    <td>{{$value.customerCode}}</td>
    <td>{{$value.name}}</td>
    <td>{{$value.contactor}}</td>
    <td>{{$value.address}}</td>
    <td>{{$value.postCode}}</td>
    <td>{{$value.createDate}}</td>
    <td>{{$value.tel}}</td>
    <td>{{$value.fax}}</td>

    <td><span style="color: #b50f11" onclick="deleteCustomer('{{$value.customerCode}}')"   >删除&nbsp;&nbsp;</span><span style="color: #4a5fb5;" onclick="updateCustomer('addUpCustomer.html','{{$value.customerCode}}')">修改</span></td>
</tr>
{{/each}}
</script>
<script>

    function selectCustomer() {
        showPage({
            currentPage: 1,
            pageSize: 3,
            url:'selectCustomer',
            templateId: 'customerTemplate',
            contentId: 'tableBody',
            params:{
                customerCode:$('#customerCode').val(),
                name:$('#name').val(),
                contactor:$('#contactor').val()
            }
        })
    }


    function updateCustomer(url,Obj) {
        Ajax.getHtml(url,function (html) {
            Ajax.post("/updateCustomer",{
                customerCode:Obj
            },function (reslut) {
                $('#customerCode').val(reslut.data.customerCode);
                $('#name').val(reslut.data.name);
                $('#password').val(reslut.data.password);
                $('#contactor').val(reslut.data.contactor);
                $('#address').val(reslut.data.address);
                $('#postCode').val(reslut.data.postCode);
                $('#tel').val(reslut.data.tel);
                $('#fax').val(reslut.data.fax);
            });
            layer.open(
                {
                    type:1,
                    title:'客户信息修改',
                    area: ['800px',['400px']],
                    content: html,
                    btn: ['确认', '取消'],
                    yes:function () {
                        Ajax.post('/updateCustomer2',{
                            customerCode:$('#customerCode').val(),
                            name:$('#name').val(),
                            password:$('#password').val(),
                            contactor:$('#contactor').val(),
                            address:$('#address').val(),
                            postCode:$('#postCode').val(),
                            tel:$('#tel').val(),
                            fax:$('#fax').val()
                        }, function (result) {
                            doResult(result, function () {
                                layer.closeAll();
                                show('customer.html');
                            })
                        })
                    }
                })
        })
    }

    function deleteCustomer(Obj) {
        var flag=window.confirm("确认删除");
        if (flag){
            Ajax.post("deleteCustomer",{
                customerCode:Obj
            },function (reslut) {
                doResult(reslut,function () {
                    show('customer.html')
                })
            })
        }
    }


    function addCustomer(url){
        Ajax.getHtml(url,
            function (html) {
                Ajax.post("/addCustomer",{},
                    function (result) {
                        $('#customerCode').val(result.data);
                    });
                layer.open(
                    {
                        type:1,
                        title:'供应商添加',
                        area: ['800px',['400px']],
                        content: html,
                        btn: ['确认', '取消'],
                        yes:function () {
                            Ajax.post('/addCustomer2',{
                                customerCode:$('#customerCode').val(),
                                name:$('#name').val(),
                                password:$('#password').val(),
                                contactor:$('#contactor').val(),
                                address:$('#address').val(),
                                postCode:$('#postCode').val(),
                                tel:$('#tel').val(),
                                fax:$('#fax').val()
                            }, function (result) {
                                doResult(result, function () {
                                    layer.closeAll();
                                    show('customer.html');
                                    layer.alert(result.msg)
                                })
                            })
                        }
                    })

            })

    }

    $(function () {

        showPage({
            currentPage: 1,
            pageSize: 3,
            url: '/customerList',
            templateId: 'customerTemplate',
            contentId: 'tableBody',
        })
    })
</script>